import KoaRouter from 'koa-router'
import { Success } from '../../../../core/HttpException'
import Auth from '../../../../middlewares/Auth'
import Config from '../../../../config/Config'
import RedisClient from '../../../../core/Redis'
import { Models } from '../../../../common/typings/model'

const router = new KoaRouter({
  prefix: `${Config.api_prefix}system/auth`,
})

/*
 * 退出登录
 */
router.post('/logout', async (ctx: Models.Ctx) => {
  await RedisClient.deleteToken(Auth.getToken(ctx)!)
  throw new Success()
})

export default router
